public class PrimeSieve {
    public static void main(String[] args) {
        int n=20000;
        boolean[] isPrime = new boolean[n + 1];
        for (int i =2; i <= n; i++) {
            isPrime[i] = true;
        }
        
        for (int p=2; p * p <= n; p++) {
            if (isPrime[p]) {
                for (int i = p * p; i <= n; i += p) {
                    isPrime[i] = false;
                }
            }
        }
        
        int count=0;
        for (int i=2; i <= n; i++) {
            if (isPrime[i]) {
                System.out.printf("%-6d", i);
                count++;
                if (count%5==0) System.out.println();
            }
        }
    }
}